package visualcbir;

import iautils.IAUtils;
import imganalysis.DataUnit;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import visualcbir.util.VSUtils;
import visualcbir.node.ModelNode;

/**
 *
 * @author sheila
 */

public class ModelComposedSimple extends ModelComposed {

    public ModelComposedSimple(){
        super();
    }

     public void getData(int idQuery, int numImages){
         
        String path = VSUtils.getProperty("imageshistograms");
        ArrayList <int[]>aiHistograms=IAUtils.readHistograms(path);

        ArrayList<DataUnit> aAllDataUnits = new ArrayList<DataUnit>();
        for (int iCurrentDimVector = 0; iCurrentDimVector < aiHistograms.size(); iCurrentDimVector++) {            
            aAllDataUnits.add(new DataUnit( iCurrentDimVector, aiHistograms.get(iCurrentDimVector) ));
        }

        final DataUnit oDataUnitQuery = aAllDataUnits.get(idQuery);
        
        Collections.sort(aAllDataUnits,new Comparator(){
            public int compare(Object o1, Object o2) {
                int iDstO1 = IAUtils.compareHistograms(((DataUnit)o1).getAiDimensionsVector(), oDataUnitQuery.getAiDimensionsVector());
                int iDstO2 = IAUtils.compareHistograms(((DataUnit)o2).getAiDimensionsVector(), oDataUnitQuery.getAiDimensionsVector());
                return (iDstO1<iDstO2)?-1:+1;
            }
        });
        
        String imgPath="";
        for (int iCurrentDU = 0; iCurrentDU < aAllDataUnits.size() && iCurrentDU < numImages; iCurrentDU++) { 
            imgPath = IAUtils.readLineFromImagesFile(aAllDataUnits.get(iCurrentDU).getId());
            this.addModel(new ModelNode(iCurrentDU, imgPath, "name", iCurrentDU, 1.0));
        }
     }
}
